package com.zky.controller;

import com.sun.prism.impl.BaseContext;
import com.zky.utils.JWTutils;
import com.zky.utils.Result;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class useController {
    private static final Logger log = LogManager.getLogger(useController.class);
    @Autowired
    JWTutils jwTutils;
    @GetMapping("/login")
    public Result login(HttpServletRequest request) {
        String token = jwTutils.createToken("13520288861");
        log.info("request:{}",request.getHeader("key1"));
        return Result.success(token);
    }
    @GetMapping("{token}")
    public Result checkToken(@PathVariable String token) {
        log.info("token:{}", token);
        String s = jwTutils.parseToken(token);
        return Result.success(s);
        //eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3Mzc3Nzk3NDEsImFjY291bnQiOiIxMzUyMDI4ODg2MSJ9.21kq5kODL5Hq6Hv8L4vfE5EPCqyok1NcdN_CVoCjbM4
    }

    @PostMapping("test01")
    public Result test01() {
        log.info("test01 start");
        return Result.success("aaaaaaa");
    }
}
